﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Transport
{
    public class HuyDatXeControl
    {
        transportEntities db;

        public HuyDatXeControl()
        {
            db = new transportEntities();
        }

        public List<huy_dat_xe> listAll()
        {
            try
            {
                return db.huy_dat_xe.ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }

        public huy_dat_xe findByID(string Id)
        {
            try
            {
                return db.huy_dat_xe.SingleOrDefault(t => t.id == Id);
               
            }
            catch (Exception)
            {
                return null;
            }
        }

        public bool insert(huy_dat_xe value)
        {
            try
            {
                db.huy_dat_xe.AddObject(value);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool update(huy_dat_xe value)
        {
            try
            {
                huy_dat_xe st = db.huy_dat_xe.SingleOrDefault(t => t.id == value.id);
                st = value;
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool delete(string Id)
        {
            try
            {
                huy_dat_xe st = db.huy_dat_xe.SingleOrDefault(t => t.id == Id);
                db.huy_dat_xe.DeleteObject(st);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}